import time

from selenium.webdriver.common.by import By

from common.untils import Lunta

class LunTaser:
    driver=""
    url=""
    def __init__(self):
        self.url="http://127.0.0.1:9580/index.html"
        self.driver=Lunta.driver
        self.driver.get(self.url)

    #搜索
    def LTaser(self):
        self.driver.implicitly_wait(5)
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.d-none.d-md-flex.me-3 > div > form > div > input").send_keys("1234")
        #点击搜索
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.d-none.d-md-flex.me-3 > div > form > div > input").click()
        #搜索第一篇文章
        time.sleep(3)
        text=self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong").text
        Lunta.getScreenShot()
        #断言是否搜索成功
        #assert text=="1234"

    #私信
    def LTiss(self):
        self.driver.implicitly_wait(5)
        Lunta.getScreenShot()
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong").click()
        self.driver.find_element(By.CSS_SELECTOR,"#btn_details_send_message").click()
        self.driver.find_element(By.CSS_SELECTOR,"#index_message_receive_content").send_keys("上转转回收了吧")
        self.driver.find_element(By.CSS_SELECTOR,"#btn_index_send_message").click()
        Lunta.getScreenShot()
        #是否发布成功弹窗
        self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div")
        Lunta.getScreenShot()

    #回复
    def LTreply(self):
        self.driver.implicitly_wait(5)
        time.sleep(5)
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong").click()
        self.driver.find_element(By.CSS_SELECTOR,"#article_details_reply > div.CodeMirror.cm-s-default.CodeMirror-wrap.CodeMirror-empty > div.CodeMirror-scroll").send_keys("哇哈哈")
        self.driver.find_element(By.CSS_SELECTOR,"#details_btn_article_reply > span").click()
        #内容为空无法发送
        Lunta.getScreenShot()
        #提示请输入内容
        self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div")

    #点赞
    def LTlike(self):
        self.driver.implicitly_wait(5)
        self.driver.find_element(By.CSS_SELECTOR,
                                 "#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong").click()
        self.driver.find_element(By.CSS_SELECTOR,"#details_btn_like_count").click()
        #提示点赞成功
        self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div > h2")
        time.sleep(1)
        Lunta.getScreenShot()
